package com.example.sunchuanjia_03;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class ProductDetailsActivity extends AppCompatActivity {
    private Button add_to_cart, btnPayNow;
    private TextView tvProductName, tvProductPrice;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_details);

        add_to_cart = findViewById(R.id.add_to_cart);
        btnPayNow = findViewById(R.id.btnPayNow);

        tvProductName = findViewById(R.id.tvProductName);
        tvProductPrice = findViewById(R.id.tvProductPrice);

        //显示商品详情
        Intent intent = getIntent();
        if(intent != null)
        {
            String[] data =(String[]) intent.getSerializableExtra("key");
            tvProductName.setText(tvProductName.getText()+data[0]);
            tvProductPrice.setText(tvProductPrice.getText()+data[1]);
        }

        //添加购物车
        add_to_cart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent2 = new Intent(ProductDetailsActivity.this, AddToCartActivity.class);
                intent2.putExtra("key2", intent);
                startActivity(intent2);
            }
        });

        //立即支付
        btnPayNow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent2 = new Intent(ProductDetailsActivity.this, DirectPayActivity.class);
                intent2.putExtra("key2", intent);
                startActivity(intent2);
            }
        });
    }
}
